///*
// *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
// *
// *  Redistribution and use in source and binary forms, with or without
// *  modification, are permitted provided that the following conditions are met:
// *
// *  Redistributions of source code must retain the above copyright notice,
// *  this list of conditions and the following disclaimer.
// *  Redistributions in binary form must reproduce the above copyright
// *  notice, this list of conditions and the following disclaimer in the
// *  documentation and/or other materials provided with the distribution.
// *  Neither the name of the dreamlu.net developer nor the names of its
// *  contributors may be used to endorse or promote products derived from
// *  this software without specific prior written permission.
// *  Author: Chill 庄骞 (smallchill@163.com)
// */
//package com.plian.system.service.dp.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.plian.Tools.*;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.dao.pm.property.PropertyBasicsDao;
//import com.plian.system.dto.dp.DisciplinaryPersonnelDTO;
//import com.plian.system.entity.dp.DisciplinaryPersonnel;
//import com.plian.system.mapper.dp.DisciplinaryPersonnelMapper;
//import com.plian.system.mybatis.base.BaseFlowService;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.service.dp.IDisciplinaryPersonnelService;
//import com.plian.system.service.sys.code.IFormCodeService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.dp.DisciplinaryPersonnelVO;
//import com.plian.system.vo.report.HeaderVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.vo.report.ReportVO;
//import com.plian.system.wrapper.dp.DisciplinaryPersonnelWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.*;
//import java.util.stream.Collectors;
//
//import static com.plian.system.constant.sys.FormStatusConstant.UNREVIEWED;
//
///**
// * 正风肃纪查处人员情况 服务实现类
// *
// * @author jianglei
// * @since 2019-12-05
// */
//@Slf4j
//@Service
//@AllArgsConstructor
//public class DisciplinaryPersonnelServiceImpl extends BaseServiceImpl<DisciplinaryPersonnelMapper, DisciplinaryPersonnel> implements IDisciplinaryPersonnelService, BaseFlowService {
//
//	private DisciplinaryPersonnelMapper disciplinaryPersonnelMapper;
//
//	private FormWorkflowService formWorkflowService;
//
//	private PropertyBasicsDao propertyBasicsDao;
//
//	private IFormCodeService formCodeService;
//
//	private DisciplinaryPersonnelWrapper disciplinaryPersonnelWrapper;
//
//	@Override
//	@Transactional(rollbackFor=RuntimeException.class)
//	public boolean saveOrUpdate(DisciplinaryPersonnel disciplinaryPersonnel) {
//		if (disciplinaryPersonnel.getId() == null) {
//			disciplinaryPersonnel.setCode(formCodeService.getCode(FormTypeConstant.DP_DISCIPLINARY_PERSONNEL_FORM));
//			disciplinaryPersonnel.setFormType(String.valueOf(FormTypeConstant.DP_DISCIPLINARY_PERSONNEL_FORM));
//			disciplinaryPersonnel.setVersion("1");
//		}
//		if (!Optional.ofNullable(disciplinaryPersonnel.getStatus()).isPresent()) {
//			disciplinaryPersonnel.setStatus(FormStatusConstant.UNREVIEWED);
//		}
//		return super.saveOrUpdate(disciplinaryPersonnel);
//	}
//
//	@Override
//	@Transactional(rollbackFor=RuntimeException.class)
//	public boolean deleteLogic(List<Long> ids) {
//		for (Long id : ids) {
//			DisciplinaryPersonnel disciplinaryPersonnel = getById(id);
//			if (disciplinaryPersonnel == null) {
//				return false;
//			}  else if (disciplinaryPersonnel.getStatus() != null &&
//					(disciplinaryPersonnel.getStatus() != FormStatusConstant.STASH && disciplinaryPersonnel.getStatus() != FormStatusConstant.UNREVIEWED)) {
//				return false;
//			}
//			formWorkflowService.deleteProcessInstance(String.valueOf(id));
//		}
//		return super.deleteLogic(ids);
//	}
//
//	@Override
//	public HashMap<String,Object> commit(String id) {
//		handleStatus(Long.valueOf(id), FormStatusConstant.FLOW);
//
//		//将需要提交的流程变量返回，用于工作流侧
//		return new HashMap<String,Object>();
//	}
//
//	@Override
//	public Boolean finish(String id) {
//		return handleStatus(Long.valueOf(id), FormStatusConstant.FINISH);
//	}
//
//	@Override
//	public Boolean reject(String id, int formState, String comment) {
//		return handleStatus(Long.valueOf(id), formState);
//	}
//
//
//	@Override
//	public ReportReturnVO summary(DisciplinaryPersonnelDTO disciplinaryPersonnelDTO) throws Exception{
//		if (StringUtil.isNotBlank(disciplinaryPersonnelDTO.getFillingDate())){
//			disciplinaryPersonnelDTO.setFillingDate(disciplinaryPersonnelDTO.getFillingDate().split(" ")[0]);
//		}
//		List<DisciplinaryPersonnelVO> disciplinaryPersonnelVOList = disciplinaryPersonnelWrapper.entityToVO(disciplinaryPersonnelMapper.summary(disciplinaryPersonnelDTO.getFillingDate(), disciplinaryPersonnelDTO.getFillingUnitIds()));
//		List<DisciplinaryPersonnelVO> data = new ArrayList<>();
//		if (CollectionUtil.isNotEmpty(disciplinaryPersonnelVOList)) {
//			List<PageData> allProperty =  propertyBasicsDao.list(null);
//			Map<String, List<DisciplinaryPersonnelVO>> map = disciplinaryPersonnelVOList.stream().collect(Collectors.groupingBy(DisciplinaryPersonnelVO::getCompanyId));
//
//			int sum = 0;
//			for (PageData org : allProperty){
//				if (map.containsKey(org.get("id"))) {
//					data.addAll(map.get(org.get("id")));
//					sum += map.get(org.get("id")).size();
//					DisciplinaryPersonnelVO vo = new DisciplinaryPersonnelVO();
//					vo.setFillingUnitName("小计：" + map.get(org.get("id")).size());
//					data.add(vo);
//				}
//			}
//			DisciplinaryPersonnelVO end = new DisciplinaryPersonnelVO();
//			end.setFillingUnitName("总计：" + sum);
//			data.add(end);
//		}
//		ReportReturnVO reportReturnVO = new ReportReturnVO();
//
//		ReportVO reportVO = new ReportVO();
//
//		reportVO
//			.addHeader(HeaderVO.builder().key("fillingUnitName").title("填报单位").build())
//			.addHeader(HeaderVO.builder().key("name").title("姓名").build())
//			.addHeader(HeaderVO.builder().key("genderName").title("性别").build())
//			.addHeader(HeaderVO.builder().key("companyName").title("单位").build())
//			.addHeader(HeaderVO.builder().key("jobName").title("职务").build())
//			.addHeader(HeaderVO.builder().key("rankName").title("职级").build())
//			.addHeader(HeaderVO.builder().key("disciplineViolations").title("违纪违规问题").build())
//			.addHeader(HeaderVO.builder().key("isBureaucracy").title("是否属于形式主义、官僚主义问题").build())
//			.addHeader(HeaderVO.builder().key("partyDisciplinary").title("党纪处分").build())
//			.addHeader(HeaderVO.builder().key("governmentSanction").title("政务处分").build())
//			.addHeader(HeaderVO.builder().key("organizationDeal").title("组织处理").build())
//			.addHeader(HeaderVO.builder().key("otherDeal").title("其他处理").build())
//			.addHeader(HeaderVO.builder().key("disposeTime").title("处分时间").build());
//		reportVO.setData(data);
//		reportReturnVO.setGrids(reportVO);
//		return reportReturnVO;
//	}
//
//	@Override
//	public List<PageData> findByIds(List<String> formIds) {
//		QueryWrapper<DisciplinaryPersonnel> queryWrapper = new QueryWrapper<>();
//		queryWrapper.in("id", Func.toLongList(StringUtils.join(formIds, StringPool.COMMA)));
//		List<DisciplinaryPersonnel> disciplinaryPersonnels = list(queryWrapper);
//		List<DisciplinaryPersonnelVO> disciplinaryPersonnelVOS =disciplinaryPersonnelWrapper.entityToVO(disciplinaryPersonnels);
//		List<PageData> pageDataList = new ArrayList<>();
//		try{
//			if (CollectionUtil.isNotEmpty(disciplinaryPersonnelVOS)){
//				for (DisciplinaryPersonnelVO vo : disciplinaryPersonnelVOS){
//					PageData pd = new PageData();
//					pd.put("id", vo.getId());
//					pd.put("UNITNAME", vo.getFillingUnitName());
//					pd.put("APPLICANTNAME", vo.getCreateUserName());
//					pd.put("applicantId", vo.getCreateUser());
//					pd.put("applyOrganizationId", vo.getFillingUnitId());
//					pd.put("formType", FormTypeConstant.DP_DISCIPLINARY_PERSONNEL_FORM);
//					pd.put("orgName", vo.getFillingUnitName());
//					pageDataList.add(pd);
//				}
//			}
//
//			return pageDataList;
//		} catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//		}
//		return pageDataList;
//	}
//
//	@Override
//	public List<Integer> getFormType() {
//		return Arrays.asList(FormTypeConstant.DP_DISCIPLINARY_PERSONNEL_FORM);
//	}
//
//	@Override
//	public void goBackToStash(String formId) {
//		handleStatus(Long.valueOf(formId), UNREVIEWED);
//	}
//
//	/**
//	 * 统一处理状态机事件方法
//	 *
//	 * @param id          主键
//	 * @param updateStatus  更新状态
//	 * @return boolean
//	 */
//	private Boolean handleStatus(Long id, int updateStatus) {
//		try {
//			DisciplinaryPersonnel disciplinaryPersonnel = getById(id);
//			/**
//			 * 设置审批人和审批时间
//			 */
//			if (updateStatus == FormStatusConstant.FINISH){
//				disciplinaryPersonnel.setApprovedUser(TokenUtil.getTokenUserId());
//				Date now = DateUtil.now();
//				disciplinaryPersonnel.setApprovedTime(now);
//			}
//			disciplinaryPersonnel.setStatus(updateStatus);
//			updateById(disciplinaryPersonnel);
//			return true;
//		} catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//			return false;
//		}
//	}
//
//}
